// app.js
App({
  globalData:{
    openid:''
  },
  comrequest: function (urls,datas,headers={'content-type':'application/x-www-form-urlencoded'},methods='POST',dataTypes='json',responseTypes='text') {
    return new Promise((resolve,reject)=>{
      wx.request({
        url: urls,
        data:datas,
        header:headers,
        method:methods,
        dataType:dataTypes,
        responseType:responseTypes,
        success:res=>{
          resolve(res.data)
        },fail:res=>{
          reject(res)
        }
      })
    })
  },
  onLaunch(){  //获取openid
    var that =this;
    wx.login({
      success: function (res) {
          if(res.code){
            that.comrequest('https://ipass.cc/myapi/userlogin.php',{code: res.code}).then(res=>{
               //存入数据库
              that.globalData.openid=res;
              })
          }
          else{
            console.log("登录失败:"+res.errMsg)
          }
        }
      })
  }
 
})